package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/15 13:22
 * @version  V1.0
 * @description:
 *
 */
func main() {

	/**
	slice01=[100 200 300] slice01Address=0xc000004480 slice01[0]Address=0xc000010400
	slice01=[100 200 300 400 500 600] slice01Address=0xc000004480 slice01[0]Address=0xc00000c300
	slice02=[100 200 300 400 500 600 700] slice02Address=0xc000004500 slice02[0]Address=0xc000052060
	slice02=[100 200 300 400 500 600 700 100 200 300 400 500 600 700] slice02Address=0xc000004500 slice02[0]Address=0xc000090000
	切片append()本质就是对数组扩容, 底层创建新的数组, 赋值给切片
	*/
	var slice01 []int = []int{100, 200, 300}
	fmt.Printf("slice01=%v slice01Address=%p slice01[0]Address=%p\n", slice01, &slice01, &slice01[0])
	slice01 = append(slice01, 400, 500, 600)
	fmt.Printf("slice01=%v slice01Address=%p slice01[0]Address=%p\n", slice01, &slice01, &slice01[0])

	slice02 := append(slice01, 700)
	fmt.Printf("slice02=%v slice02Address=%p slice02[0]Address=%p\n", slice02, &slice02, &slice02[0])
	//蠕虫增长 fatal error: out of memory
	slice02 = append(slice02, slice02...)
	fmt.Printf("slice02=%v slice02Address=%p slice02[0]Address=%p\n", slice02, &slice02, &slice02[0])

	fmt.Println("=====================================")
	var slice03 []int = []int{1, 2, 3, 4, 5}
	slice04 := make([]int, 10)
	fmt.Println("slice04 use make created and default cap=", cap(slice04))
	//切片拷贝
	copy(slice04, slice03)
	fmt.Println(slice03)
	fmt.Println(slice04)

}
